

package com.maoshi.shop.distribution.platform.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.annotation.SysLog;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.distribution.comment.model.DistributionUserInfo;
import com.maoshi.shop.distribution.comment.service.DistributionUserInfoService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author xwc
 * @date 2019-04-15 16:59:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/distribution/distributionUserInfo")
public class DistributionUserInfoController {


    private final DistributionUserInfoService distributionUserInfoService;

    /**
     * 分页查询
     *
     * @param page                 分页对象
     * @param distributionUserInfo
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<DistributionUserInfo>> getDistributionUserInfoPage(PageParam<DistributionUserInfo> page, DistributionUserInfo distributionUserInfo) {
        return ResponseEntity.ok(distributionUserInfoService.page(page, new LambdaQueryWrapper<DistributionUserInfo>()));
    }


    /**
     * 通过id查询
     *
     * @param distributionUserInfoId id
     * @return 单个数据
     */
    @GetMapping("/info/{distributionUserInfoId}")
    public ResponseEntity<DistributionUserInfo> getById(@PathVariable("distributionUserInfoId") Long distributionUserInfoId) {
        return ResponseEntity.ok(distributionUserInfoService.getById(distributionUserInfoId));
    }

    /**
     * 新增
     *
     * @param distributionUserInfo
     * @return 是否新增成功
     */
    @SysLog("新增")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserInfo:save')")
    public ResponseEntity<Boolean> save(@RequestBody @Valid DistributionUserInfo distributionUserInfo) {
        return ResponseEntity.ok(distributionUserInfoService.save(distributionUserInfo));
    }

    /**
     * 修改
     *
     * @param distributionUserInfo
     * @return 是否修改成功
     */
    @SysLog("修改")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserInfo:update')")
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionUserInfo distributionUserInfo) {
        return ResponseEntity.ok(distributionUserInfoService.updateById(distributionUserInfo));
    }

    /**
     * 通过id删除
     *
     * @param distributionUserInfoId id
     * @return 是否删除成功
     */
    @SysLog("删除")
    @DeleteMapping("/{distributionUserInfoId}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserInfo:delete')")
    public ResponseEntity<Boolean> removeById(@PathVariable Long distributionUserInfoId) {
        return ResponseEntity.ok(distributionUserInfoService.removeById(distributionUserInfoId));
    }

}
